package thermologic.gui;

import java.text.SimpleDateFormat;
import javax.swing.table.AbstractTableModel;
import thermologic.core.Channel;

/**
 *
 * @author mrivadeneira
 */
public class ConfigurationDataModel extends AbstractTableModel
{
    private static final int NUM_ROWS = 8;
    private static final int NUM_COLS = 2;
            
    private Channel channel;
    private String[] colHeaders;
    
    public ConfigurationDataModel()
    {
        colHeaders = new String[NUM_COLS];
        
        colHeaders[0] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.traceTable.col1");
        
        colHeaders[1] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.traceTable.col2");
    }
    
    private Object[][] getConfigAsTable()
    {
        Object table[][] = new Object[NUM_ROWS][NUM_COLS];
        
        table[0][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param1");
        
        table[1][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param2");
        
        table[2][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param3");
        
        table[3][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param4");
        
        table[4][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param5");
        
        table[5][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param6");
        
        table[6][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param7");
        
        table[7][0] = java.util.ResourceBundle.getBundle("properties/language").
                getString("thermologic.configTable.param8");
        
        if(channel != null)
        {
            SimpleDateFormat format = new SimpleDateFormat(
                    java.util.ResourceBundle.getBundle("properties/language").getString("thermologic.format.dateAndTime")
                );
            
            table[0][1] = channel.getLabel();
            table[1][1] = channel.getSampleRate();
            
            if(channel.getStartTime() != null)
            {
                table[2][1] = format.format(channel.getStartTime());
            }
            
            if(channel.getEndTime() != null)
            {
                table[3][1] = format.format(channel.getEndTime());
            }
            
            table[4][1] = channel.getAlarmLow();        
            table[5][1] = channel.getAlarmHigh();
            table[6][1] = channel.getResolution();
            table[7][1] = channel.getUnit();
        }
                
        return table;
    }
    
    public void setChannel(Channel channel)
    {
        this.channel = channel;
    }
    
    public int getRowCount()
    {
        return NUM_ROWS;
    }

    public int getColumnCount() {
        return NUM_COLS;
    }
    
    @Override
    public String getColumnName(int col)
    {
        return colHeaders[col];
    }

    public Object getValueAt(int row, int col)
    {
        return getConfigAsTable()[row][col];
    }
    
}
